package stream;

import java.util.*;
import java.util.stream.Collectors;

public class StreamTest4 {
    public static void main(String[] args) {
        List<Student> students = new ArrayList<>();
        students.add(new Student("至尊宝", 26, 178));
        students.add(new Student("牛魔王", 33, 175));
        students.add(new Student("蜘蛛精", 22, 160));
        students.add(new Student("蜘蛛精", 22, 160));
        students.add(new Student("白晶晶", 24, 167));
        students.add(new Student("紫霞", 25, 173));
        // 身高超过168有几人
        long size = students.stream().filter(s -> s.getHeight() > 168).count();
        System.out.println(size);

        // 身高最高的人
        Student s1 = students.stream().max((Comparator.comparingDouble(Student::getHeight))).get();
        System.out.println(s1);

        // 最矮的人
        Student s2 = students.stream().min((Comparator.comparingDouble(Student::getHeight))).get();
        System.out.println(s2);

        // 身高超过170的转入新集合
        List<Student> list = students.stream().filter(s -> s.getHeight() > 170).collect(Collectors.toList());
        System.out.println(list);

        Set<Student> set = students.stream().filter(s -> s.getHeight() > 170).collect(Collectors.toSet());
        System.out.println(set);

        Map<String, Double> map = students.stream().distinct()
                .filter(a -> a.getHeight() > 170).collect(Collectors.toMap(Student::getName, Student::getHeight));
        System.out.println(map);
    }
}

